package com.wfm.listenerevent;


import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

@Component
public class OrderServiceImpl implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher publisher;

    public void buy(Order order){
        System.out.println("下单"+order.toString());

        OrderEvent orderEvent = new OrderEvent(this, order);
        publisher.publishEvent(orderEvent);
    }


    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher=applicationEventPublisher;
    }
}
